package com.goldsprite.gameframeworks.ecs.component;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.goldsprite.gameframeworks.ecs.system.GameSystem;

public class TiledMapComponent extends RenderableComponent {
	private OrthogonalTiledMapRenderer tmxRender;
	private OrthographicCamera worldCamera;

	public TiledMapComponent() {
	}

	public void init(TiledMap tiledmap, float unitScale) {
		//设置相机
		worldCamera = GameSystem.worldCamera;

		//初始化自定义瓦片地图渲染器
		tmxRender = new OrthogonalTiledMapRenderer(tiledmap, unitScale);// 创建渲染器
	}

	//绘制tmx地图
	@Override
	public void render(Batch batch, float delta) {
		// 设置渲染器的视图矩阵
		tmxRender.setView(worldCamera);
		// 渲染地图
		tmxRender.render();
	}


}

